
public class Animal implements Cloneable {
    private int age;
    private String name;

    public void eat() {
        System.out.println("eat");
    }

    public Animal(int age, String name) {
        this.age = age;
        this.name = name;
    }

    @Override
    public Object clone() {
        try {
            return super.clone();
        } catch (CloneNotSupportedException e) {
            return null;
        }
    }

    public void setAge(int age) {
        this.age = age;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return String.format("[Animal: %s,name:%s,age:%s]", this.hashCode(), this.name, this.age);
    }

    public static void main(String[] args) {
        Animal a1 = new Animal(1, "a");
        Animal a2 = (Animal) a1.clone();
        a2.setAge(2);
        System.out.println(a1.toString());
        System.out.println(a2.toString());
    }

}
